<?php
define('STATIC_CSS_FOLDER', 'Public/Css/');
define('STATIC_JS_FOLDER', 'Public/Js/');

function get_static_file($files, $customBaseFolder = NULL, $item = 'Home', $get_all = false) {

	/*静态文件版本号*/
	$static_vision = '20160140';

	if ($get_all) {
		return $static_vision;
	}

	$files = is_array($files) ? $files : (array) $files;
	if (empty($customBaseFolder)) {
		$cssFolder = STATIC_CSS_FOLDER . "/" . $item;
		$jsFolder  = STATIC_JS_FOLDER;
	} else {
		$customBaseFolder = trim($customBaseFolder, '/');
		$cssFolder        = STATIC_CSS_FOLDER . $item . "/" . $customBaseFolder;
		$jsFolder         = STATIC_JS_FOLDER . $item . "/" . $customBaseFolder;
	}
	foreach ($files as $v) {
		$paras    = explode('.', $v); //dump ( $paras );
		$filetype = $paras[count($paras) - 1]; //dump ( $filetype );
		array_pop($paras);
		$file_full_name = $v;
		if (!empty($customBaseFolder)) {
			//给指定目录下的文件设定版本号
			$v = $customBaseFolder . '/' . $v;
		}
		if (strtolower($filetype) === 'css') {
			@$print_str[] = '<link rel="stylesheet" type="text/css" href="' . C('HTTP_STATIC') . '/' . $cssFolder . '/' . $file_full_name . '?v=' . $static_vision . '" />';
		} else if (strtolower($filetype) === 'js') {
			@$print_str[] = '<script type="text/javascript" src="' . C('HTTP_STATIC') . '/' . $jsFolder . '/' . $file_full_name . '?v=' . $static_vision . '"></script>';
		}
	}
	return implode('', $print_str);
}
?>
